<template>

        <div class="mod-major">
            <el-form :inline="true">
                <el-form-item>
                    <el-input v-model="search.majorName" placeholder="请输入学号名称">
                    </el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="searchMajor()">搜索
                    </el-button>
                </el-form-item>

            </el-form>

            <el-table :data="studentList" row-key="sid"  v-loading="dataListLoading"
                style="width: 100%  ">
                <el-table-column prop="sid" header-align="left" align="left" min-width="100" label="学号">
                </el-table-column>
                <el-table-column prop="name" header-align="center" align="center" min-width="100" label="姓名">
                </el-table-column>
                <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="isAuth('eascourse:scores:save')" type="text" size="small"
                            @click="addOrUpdateHandle(scope.row.sid)">评分/查看评分</el-button>

                    </template>
                </el-table-column>
            </el-table>
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
                :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
                layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
            <!-- 弹窗, 新增 / 修改 -->
            <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
        </div>

</template>

<script>
import { curriculumApi } from '@/api/course';
import { studentApi } from '@/api/student'
import { treeDataSetParent } from '@/utils';
import addOrUpdate from './scores-add-or-update.vue';

export default {
    components: {
        addOrUpdate
    },
    props: {},
    data() {
        return {
            studentList: [],
            courseInfo:{
                courseId:null,
                teacherId:null
            },
            addOrUpdateVisible: false,
            pageIndex: 1,
            pageSize: 10,
            totalPage: 0,
            dataListSelections: [],
            dataListLoading: true,
            search: {
                majorName: '',
                deptName: '',
                sid: '',
                name: ''

            }
        };
    },
    watch: {},
    computed: {},
    methods: {
        init(courseId,teacherId){
            this.courseInfo.courseId=courseId
            this.courseInfo.teacherId=teacherId
          console.log(this.courseInfo)
            this.getDataList();
            console.log(this.courseInfo);
        },
        getDataList() {
            this.dataListLoading = true
            let data = Object.assign(this.courseInfo,
                {
                    limit: this.pageSize,
                    page: this.pageIndex,
                    // name:this.search
                })
            curriculumApi.getCourseStudent(data).then(({ page }) => {
                this.studentList = page.list
                this.dataListLoading = false
                this.totalPage = page.totalPage

            }).catch(e => {
                this.$message({
                    message: '加载失败',
                    type: 'error',
                    duration: 1500,
                    onClose: () => {
                        this.dataListLoading = false
                    }
                })

            })

        },
        searchMajor() {
            this.getDataList()
        },
        addOrUpdateHandle(sid) {
            this.addOrUpdateVisible = true
            this.$nextTick(() => {

                this.$refs.addOrUpdate.init(sid,this.courseInfo.courseId)
            })
        },
        // 每页数
        sizeChangeHandle(val) {
            this.pageSize = val
            this.pageIndex = 1
            this.getDataList()
        },
        // 当前页
        currentChangeHandle(val) {
            this.pageIndex = val
            this.getDataList()
        },
        // 多选
        selectionChangeHandle(val) {
            this.dataListSelections = val
        },


    },
    created() {

    },
    mounted() {
      this.getDataList()
    }
};
</script>

<style lang="scss">
//
.demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

<style lang="scss" scoped>
.el-card {
    max-width: 60rem;
    min-width: 34rem;
    margin: 5rem auto;
}
</style>
